<!DOCTYPE pre PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <link href="./css/style.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
	<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
	<script type="text/javascript" src="./js/scrolltable.js"></script>
	<script type="text/javascript" src="./js/update.js"></script>
	<script type="text/javascript" src="./js/popupInfo.js"></script>
</head>
<body>
<pre>
<?php
session_start();
error_reporting(E_ALL);
require_once 'class/config.php';
//phpinfo();
$database = DataBase::getInstance();
$showTreaties = new ShowTreaties();
$treaties = $database->getTreaties();
$countries = $database->getCountries();
$content = $database->getContent();
?>
<div id="container">
<div id="header">
  <button id="update">Update</button>
  <div id="updateConfirmation" style="display:none">
    <p>Updating data will give you the latest information but you will have to 
      wait for about a minute or two.</p>
    <p>Do you want to continue?</p>
    
  </div>
</div>
<div id="head">
<?php 
//foreach ($treaties as $treaty){
//	echo $treaty['treatyID'] . '. ' . $treaty['title'] . '<br />';
//}
?>
</div>
<div id="content">
<table class="tbl1 scroll">
<?php 
$i = 1;
$j = 1;
?>
<thead>
	<tr>
		<th style="width:200px" />
	<?php
	foreach ($treaties as $treaty){
	?>
		<th class="titleTrigger" id="<?php echo $treaty['treatyID'];?>">
			<a href="treatyInfo.php?treatyID=<?php echo $treaty['treatyID'];?>">
				<?php echo $treaty['treatyID']; ?>
			</a>
			<div class="titlePop-up" id="titlePop-up<?php echo $treaty['treatyID'];?>">
				<?php 
				echo 'Treaty title: ' . $treaty['title'];
				?>
			</div>
		</th>
	<?php 	
	} 
	?>
<!-- 		<th style="width:1200px" />-->
	</tr>
	</thead>
	<tbody>
<?php 
foreach ($countries as $country){
	?>
	<tr>
	<td style="width:200px" class="countryStyle"><b><?php echo $country['countryName']; ?></b></td>
	<?php 
	foreach ($treaties as $treaty){
		$i++;
		$column = false;
		foreach ($content as $contentObject){
			$j++;
			if ($country['countryName'] == $contentObject['countryName'] &&
				$treaty['title'] == $contentObject['title']){
					if ($contentObject['signature'] != '0000-00-00'){
		?>
		<td class="trigger" style="background: green" id="<?php echo $contentObject['cTreatyID'];?>">
		<?php 
		//				echo 'signed';
						$column = true;
					} else {
		?>
		<td class="trigger" style="background: yellow" id="<?php echo $contentObject['cTreatyID'];?>">
		<?php 
		//				echo 'ratified';
						$column = true;
					}
					break;
				} 
		}
		if (!$column){
		?>
		<td style="background: gray">
		<?php 
	//		echo 'unsigned';
		}
		?>
		</td>
		<?php 
	}
	?>
	</tr>
	<?php 
}
?>
</tbody>
</table>
</div>
<div id="footer"></div>
</div>
</pre>
<?php 
foreach ($content as $contentObject){
	?>
	<div class="pop-up" id="pop-up<?php echo $contentObject['cTreatyID'];?>">
		<?php 
		echo 'Treaty title: ' . $contentObject['title'];
		echo '<br />Participant name: ' . $contentObject['countryName'];
		if (isset($contentObject['ratification']) && $contentObject['ratification'] != '0000-00-00'){
			echo '<br />Ratification date: ' . $contentObject['ratification'];
		}
		if (isset($contentObject['signature']) && $contentObject['signature'] != '0000-00-00'){
			echo '<br />Signature date: ' . $contentObject['signature'];
		}
		?>
	</div>
	<?php
}
?>
</body>
</html>
